import 'package:flutter/material.dart';

import './ProductContent/ProductContentFirst.dart';
import './ProductContent/ProductContentSecond.dart';
import './ProductContent/ProductContentThird.dart';
import '../services/ScreenAdatper.dart';
import '../widget/jdButton.dart';
import '../config/config.dart';
import 'package:dio/dio.dart';
import '../model/ProdicContentModel.dart';
import '../widget/loaddingWidget.dart';
import '../services/EventBus.dart';
class ProductContentPage extends StatefulWidget {
  final arguments;
  ProductContentPage({Key key,this.arguments}) : super(key: key);
  
  
  _ProductContentPageState createState() => _ProductContentPageState();
}

class _ProductContentPageState extends State<ProductContentPage> {
  ProdicContentItem _productContent;
  List _productContentList = [];
  @override
  void initState() { 
    super.initState();
    _getProdicContent();
  }

  _getProdicContent()async{
      var api = "${Config.domain}api/pcontent?id=${widget.arguments['id']}";
      print(api);
      var reslut = await new Dio().get(api);
      var productContent = new ProdicContentModel.fromJson(reslut.data); 
      setState(() {
        this._productContent = productContent.result;
        this._productContentList.add(productContent.result);
      });
  }
  @override
  Widget build(BuildContext context) {
    print(widget.arguments['id']);
    return DefaultTabController(
      length: 3,
      child: Scaffold(
          appBar:AppBar(
            title: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                 Container(
                   width: ScreenAdatper.width(400),
                   child: TabBar(
                    indicatorColor:Colors.red,
                    indicatorSize:TabBarIndicatorSize.label,
                    tabs: <Widget>[
                      Tab(
                        child: Text("商品"),
                      ),
                      Tab(
                        child: Text("详情"),
                      ),
                      Tab(
                        child: Text("评论"),
                      )
                    ],
                  ),
                 )
                ],
              ),
              actions: <Widget>[
                IconButton(
                  icon: Icon(Icons.more_horiz),
                  onPressed: (){
                    showMenu(
                      context:context,
                      position: RelativeRect.fromLTRB(ScreenAdatper.width(600), 85, 5, 0),
                      items: [
                        PopupMenuItem(
                          child: Row(
                            children: <Widget>[
                              Icon(Icons.home),
                              Text("首页")
                            ],
                          ),
                        ),
                        PopupMenuItem(
                          child: Row(
                            children: <Widget>[
                              Icon(Icons.search),
                              Text("搜索")
                            ],
                          ),
                        )
                      ]
                    );
                  },
                )
              ],
          ),
          body: _productContentList.length > 0 ? Stack(
            children: <Widget>[
              TabBarView(
                children: <Widget>[
                  ProductContentFirst(this._productContentList),
                  ProductContentSecond(this._productContentList),
                  ProductContentThird()
                ],
              ),
              Positioned(
                width: ScreenAdatper.width(750),
                height: ScreenAdatper.height(80),
                bottom: 0,
                child: Container(
                  decoration: BoxDecoration(
                    border: Border(
                      top: BorderSide(
                        width: 1,
                        color: Colors.black26
                      )
                    ),
                    color: Colors.white
                  ),
                  // color: Colors.red,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Container(
                        margin: EdgeInsets.only(top:  ScreenAdatper.height(4)),
                        width: ScreenAdatper.width(150),
                        child: Column(
                          children: <Widget>[
                            Icon(Icons.shopping_cart),
                            Text("购物车")
                          ],
                        ),
                      ),
                      Expanded(
                        flex: 1,
                        child:Container(
                          alignment: Alignment.center,
                          child:JdButtoon(
                            color: Colors.red,
                            text: '加入购物车',
                            onTap: (){
                              eventBus.fire(new ProductContentEvent("加入购物车"));
                            },
                          )  
                        ) ,
                      ),
                      Expanded(
                        flex: 1,
                        child:Container(
                          alignment: Alignment.center,
                          child:JdButtoon(
                            color: Colors.orange,
                            text: '立即购买',
                            onTap: (){
                              eventBus.fire(new ProductContentEvent("立即购买"));
                            },
                          )  ,
                        ) ,
                      )
                    ],
                  ),
                ),
              )
            ],
          ) : LoaddingWidget(hasMore: false,),
        )
    );
  }
}

